<!DOCTYPE html>
<html>
    <head>
        <!-- 页面meta -->
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>传智健康</title>
        <meta name="description" content="传智健康">
        <meta name="keywords" content="传智健康">
        <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
        <!-- 引入样式 -->
        <link rel="stylesheet" href="../css/style.css">
        <link rel="stylesheet" href="../plugins/elementui/index.css">
    </head>

    <!-- 引入组件库 -->
    <script src="../js/vue.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <script src="../js/jquery.min.js"></script>
    <script src="../plugins/echarts/echarts.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <body class="hold-transition">
    <div id="app">
        <div class="content-header">
            <h1>统计分析
                <small>会员数量</small>
            </h1>
            <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
                <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                <el-breadcrumb-item>统计分析</el-breadcrumb-item>
                <el-breadcrumb-item>会员数量</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="app-container">     <!-- container 容器 -->
            <div class="box">

                <!--        标签指定时间 去查询该时间段获取的会员数量   -->
                <div class="block" style="height: 50px;text-align: center;display:block;">
                    <span class="demonstration" >日期区间</span>
                    <el-date-picker
                            v-model="value1"
                            v-model="value2"
                            type="daterange"
                            align="right"
                            unlink-panels
                            range-separator="至"
                            start-placeholder="开始月份"
                            end-placeholder="结束月份"
                            :picker-options="pickerOptions">
                    </el-date-picker>
                    <el-button @click="findMemberDate()" class="dalfBut">查询</el-button>
                </div>

                <div style="height: 50px">
                    <HR style="FILTER:alpha(opacity=100,finishopacity=0,style=3)" width="80%"color=#FF0000 SIZE=3>
                </div>

                <!--            指定时间获取会员数量-->
                <div id="appoint" style="height: 600px; /*background-image: url('../img/gif/dajia.gif');background-size:cover;*/">

                </div>

                <div style="height: 50px">
                    <HR style="FILTER:alpha(opacity=100,finishopacity=0,style=3)" width="80%"color=#FF0000 SIZE=3>
                </div>

<!--            所有时间段获取会员数量-->
                <div id="chart1" style="height:600px; /*background-image: url('../img/gif/dajia.gif');background-size:cover;*/">

                </div>


            </div>
        </div>
    </div>
    </body>
        <script type="text/javascript">

        var vue = new Vue({
            el: "#app",
            data: {
                backendUrl: "http://localhost:82",
                pickerOptions: {
                    shortcuts: [{
                        text: '最近一周',
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                            picker.$emit('pick', [start, end]);
                        }
                    }, {
                        text: '最近一个月',
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                            picker.$emit('pick', [start, end]);
                        }
                    }, {
                        text: '最近三个月',
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                            picker.$emit('pick', [start, end]);
                        }
                    }]
                },
                value1: ''

            },
            methods: {

                findMemberDate(){
                    console.log("this.value1  ---------    " + this.value1);
                    axios.defaults.withCredentials = true;/*如果要使用安全框架,必须携带cookie*/
                    axios.post(this.backendUrl + "/report/getDateMemberNumber.do",this.value1).then((res)=>{
                        console.log("返回成功" + res);
                        myChart2.setOption(
                            {
                                title: {
                                    text: '指定时间段的会员数量'
                                },
                                tooltip: {},
                                legend: {
                                    data: ['会员数量']
                                },
                                xAxis: {
                                    data: res.data.data.months
                                },
                                yAxis: {
                                    type: 'value'
                                },
                                series: [{
                                    name: '会员数量',
                                    type: 'line',
                                    data: res.data.data.memberCount
                                }]
                            });
                    }).catch((err)=>{
                        console.log("返回失败" + err);
                        this.$message({
                            type:"error",
                            message:err.date.date.message
                        })
                    });
                }
            }
        });
        // 基于准备好的dom，初始化echarts实例
        var myChart1 = echarts.init(document.getElementById('chart1'));
        var myChart2 = echarts.init(document.getElementById('appoint'));
        // 使用刚指定的配置项和数据显示图表。

        axios.defaults.withCredentials = true;/*如果要使用安全框架,必须携带cookie*/
        axios.get("http://localhost:82/report/getMemberReport.do").then((res) => {
            console.log(res);
            myChart1.setOption(
                {
                    title: {
                        text: '所有时间段的会员数量'
                    },
                    tooltip: {},
                    legend: {
                        data: ['会员数量']
                    },
                    xAxis: {
                        data: res.data.data.months
                    },
                    yAxis: {
                        type: 'value'
                    },
                    series: [{
                        name: '会员数量',
                        type: 'line',
                        data: res.data.data.memberCount
                    }]
                });
        });

        </script>
    <script>

    </script>
</html>
